package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TPersonnelRecordVo;
import com.ruoyi.system.basicInformation.bo.TPersonnelRecordQueryBo;
import com.ruoyi.system.basicInformation.bo.TPersonnelRecordAddBo;
import com.ruoyi.system.basicInformation.bo.TPersonnelRecordEditBo;
import com.ruoyi.system.basicInformation.service.ITPersonnelRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 在船人员备案Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "在船人员备案控制器", tags = {"在船人员备案管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/record")
public class TPersonnelRecordController extends BaseController {

    private final ITPersonnelRecordService iTPersonnelRecordService;

    /**
     * 查询在船人员备案列表
     */
    @ApiOperation("查询在船人员备案列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:list')")
    @GetMapping("/list")
    public TableDataInfo<TPersonnelRecordVo> list(TPersonnelRecordQueryBo bo) {
        startPage();
        List<TPersonnelRecordVo> list = iTPersonnelRecordService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出在船人员备案列表
     */
    @ApiOperation("导出在船人员备案列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:export')")
    @Log(title = "在船人员备案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TPersonnelRecordVo> export(TPersonnelRecordQueryBo bo) {
        List<TPersonnelRecordVo> list = iTPersonnelRecordService.queryList(bo);
        ExcelUtil<TPersonnelRecordVo> util = new ExcelUtil<TPersonnelRecordVo>(TPersonnelRecordVo.class);
        return util.exportExcel(list, "在船人员备案");
    }

    /**
     * 获取在船人员备案详细信息
     */
    @ApiOperation("获取在船人员备案详细信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:query')")
    @GetMapping("/{id}")
    public AjaxResult<TPersonnelRecordVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTPersonnelRecordService.queryById(id));
    }

    /**
     * 新增在船人员备案
     */
    @ApiOperation("新增在船人员备案")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:add')")
    @Log(title = "在船人员备案", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TPersonnelRecordAddBo bo) {
        return toAjax(iTPersonnelRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改在船人员备案
     */
    @ApiOperation("修改在船人员备案")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:edit')")
    @Log(title = "在船人员备案", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TPersonnelRecordEditBo bo) {
        return toAjax(iTPersonnelRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除在船人员备案
     */
    @ApiOperation("删除在船人员备案")
    @PreAuthorize("@ss.hasPermi('basicInformation:record:remove')")
    @Log(title = "在船人员备案" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTPersonnelRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
